/**
 * 消息提示
 */

let vue = undefined;

function createMsg() {
    if (vue) return vue;

    let elId = '#message1026';
    if ($(elId).length == 0) {
        $("body").append('<div id="message1026"></div>');
    }

    let loadingHandle;

    vue = new Vue({
        el: elId,
        methods: {
            show: function (message) {
                this.$message(message);
            },
            alert: function (message) {
                this.$alert(message);
            },
            confirm: function (message, title, okCallback, cancelCallback) {
                this.$confirm(message, title, {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    okCallback && okCallback();
                }).catch(() => {
                    cancelCallback && cancelCallback();
                });
            },
            messageBox: function (message, title, callback) {
                this.$alert(message, title, {
                    confirmButtonText: '确定',
                    callback: action => {
                        callback && callback(action);
                    }
                });
            },
            loading: function (msg) {
                loadingHandle = this.$loading({
                    lock: true, //lock的修改符--默认是false
                    text: msg, //显示在加载图标下方的加载文案
                    spinner: 'el-icon-loading', //自定义加载图标类名
                    background: 'rgba(0, 0, 0, 0.5)', //遮罩层颜色
                    target: document.querySelector('#threeContainer') //loadin覆盖的dom元素节点
                })
            },
            loadingClose: function () {
                loadingHandle && loadingHandle.close()
            }
        }
    });

    return vue;
}

export { createMsg }
